﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Protoss
{
	public abstract class ActionCallChronoBoost : Action
	{
		protected ActionCallChronoBoost() { }
		public abstract ProtossState.ProtossProductionBuilding GetProductionBuilding(ProtossState state);
		public override bool HaveResources(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			if (GetProductionBuilding(state).NotChronoBoosted == 0) return false;
			for (int c = 0; c < state.Nexus_Energy.Count; c++)
				if (state.Nexus_Energy[c] >= 25)
					return true;
			return false;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return state.Nexus.Count > 0 && GetProductionBuilding(state).Count > 0;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return state.Nexus.Total == 0 || GetProductionBuilding(state).Total == 0;
		}

		public override void Execute(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			for (int c = 0; c < state.Nexus_Energy.Count; c++)
				if (state.Nexus_Energy[c] >= 25)
				{
					state.Nexus_Energy[c] -= 25;
					break;
				}
			GetProductionBuilding(state).ChronoBoosted++;
			bo.AddAction(state.Time + 20, new ActionGeneric("ActionFailedChronoBoost", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ProtossState ibostate = ibo.State as ProtossState;
				GetProductionBuilding(ibostate).ChronoBoosted--;
			}));
		}

	}

	public class ActionCallChonoBoostOnNexus : ActionCallChronoBoost
	{
		public static ActionCallChonoBoostOnNexus Instance = new ActionCallChonoBoostOnNexus();
		private ActionCallChonoBoostOnNexus() { }
		public override ProtossState.ProtossProductionBuilding GetProductionBuilding(ProtossState bo) { return bo.Nexus; }
	}
	public class ActionCallChonoBoostOnRoboticsFacility : ActionCallChronoBoost
	{
		public static ActionCallChonoBoostOnRoboticsFacility Instance = new ActionCallChonoBoostOnRoboticsFacility();
		private ActionCallChonoBoostOnRoboticsFacility() { }
		public override ProtossState.ProtossProductionBuilding GetProductionBuilding(ProtossState bo) { return bo.RoboticsFacility; }
		public IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceRoboticsFacility.Instance } };
				return m_Requirements;
			}
		}
	}
	public class ActionCallChonoBoostOnStargate : ActionCallChronoBoost
	{
		public static ActionCallChonoBoostOnStargate Instance = new ActionCallChonoBoostOnStargate();
		private ActionCallChonoBoostOnStargate() { }
		public override ProtossState.ProtossProductionBuilding GetProductionBuilding(ProtossState bo) { return bo.Stargate; }
		public IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceStargate.Instance } };
				return m_Requirements;
			}
		}
	}
	public class ActionCallChonoBoostOnGateway : ActionCallChronoBoost
	{
		public static ActionCallChonoBoostOnGateway Instance = new ActionCallChonoBoostOnGateway();
		private ActionCallChonoBoostOnGateway() { }
		public override ProtossState.ProtossProductionBuilding GetProductionBuilding(ProtossState bo) { return bo.Gateway; }
		public IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceGateway.Instance } };
				return m_Requirements;
			}
		}
	}
}
